9  Making a Code Appendix

An aspect of Open Science is being transparent and open about your code. This is especially important when engaged in data analysis. Making your code available helps convey a sense of trustworthiness in you as an author and analyst.

Making your code available does not mean that your code must be perfect. No one expects code to perfect. The idea in sharing the code that you used is so that other people can examine your code and reproduce your results. They (and your future self) can then look at those results with what you’ve written and make sure everything is coherent and logical.

When working in a single document, we can leverage Quarto’s powers to automatically create an appendix of all of your code chunks. In essence, we’ll make use of Quarto’s ability to take your code chunks and moved them to the end of the document. This helps to make your data analysis focused on what you’re finding/discovering without cluttering the body of your report with distracting code.

9.1 Code for the Appendix

To create a Code Appendix, you will need to go to the bottom of your Quarto document. There you’ll want to copy what appearss in Listing 9.1.

Listing 9.1: Code Chunk for Creating Code Appendix
\{\{< pagebreak >\}\}  
# Code Appendix
```{r}
#| label: codeAppend
#| ref-label: !expr knitr::all_labels()
#| echo: true
#| eval: false

```
CautionRemove the Backslashes

In Listing 9.1, you’ll notice that there are four backslashes (i.e., \) that appear in the first line (with pagebreak). You will need to remove these backslashes when you copy this code into your document. They appear here so that you can see this line of code.

Outside of the four code chunk options (and one empty line), there should be nothing else in your final code chunk. Additionally, there should be nothing except empty lines after the closing three backticks for this code chunk. After putting this code into your Quarto document, the next time you render the file, your Code Appendix will get generated. Additionally, as you edit your file and re-render, the Code Appendix will automatically update.